package com.pdg.mcplugin.misterdevtool;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.PluginManager;

import com.pdg.mcplugin.common.ArgumentList;
import com.pdg.mcplugin.common.baseclasses.FeatureManagerBase;
import com.pdg.mcplugin.common.baseclasses.PluginBase;

public class MisterDevtool extends PluginBase{

	private static final String COMMAND_MISTER_DEVTOOL = "mdt";

	private PlayerInteractEventSpy pieSpy = null;
	public PlayerInteractEventSpy getPieSpy(){
		if(pieSpy==null){
			pieSpy = new PlayerInteractEventSpy(this);
		}
		return pieSpy;
	}
	
	private FeatureManagerBase<MisterDevtool,MDTFeatures> featureManager = null;
	public FeatureManagerBase<MisterDevtool,MDTFeatures> getFeatureManager(){
		if(featureManager==null){
			featureManager = new FeatureManagerBase<MisterDevtool,MDTFeatures>(this);
		}
		return featureManager;
	}
	
	
	private CommandProcessor commandProcessor=null;
	private CommandProcessor getCommandProcessor() {
		if(commandProcessor==null){
			commandProcessor = new CommandProcessor(this);
		}
		return commandProcessor;
	}
	//plugin manager
	private PluginManager pluginManager;
	public PluginManager getPluginManager(){
		if(pluginManager==null){
			pluginManager = getServer().getPluginManager();
		}
		return pluginManager;
	}

	@Override
	protected void disablePlugin() {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected boolean enablePlugin() {
		saveDefaultConfig();
		getPluginManager().registerEvents(getPieSpy(), this);
		return true;
	}

	//handle commands
	public boolean onCommand(CommandSender theCommandSender, Command theCommand, String theLabel, String[] theArgs){
		ArgumentList theArgumentList = new ArgumentList(theArgs);
		if(theCommand.getName().equalsIgnoreCase(COMMAND_MISTER_DEVTOOL)){
			return getCommandProcessor().processCommand(theCommandSender,theArgumentList);
		}
		return false;
	}
}
